/* 
 * File:   hfgl_polygon.cpp
 * Author: Satan
 * 
 * Created on September 12, 2012, 11:11 PM
 */

#include "hfgl/hfgl_polygon.h"
#include "hfgl/hfgl_point.h"

hfgl_polygon::hfgl_polygon() 
{
    points = NULL;
    mode = GL_LINE_LOOP;
    array_x = 0;
    array_y = 0;
    color[0] = 0.0;
    color[1] = 0.0;
    color[2] = 0.0;
}

hfgl_polygon::hfgl_polygon(GLenum _mode, std::vector<hfgl_point>* surface, GLfloat cR, GLfloat cG, GLfloat cB) : mode(_mode)
{
    color[0] = cR;
    color[1] = cG;
    color[2] = cB;    

    array_x = 2;
    array_y = surface->size();
    points = new GLfloat[array_x * array_y];
    int i = 0;
    for(std::vector<hfgl_point>::iterator it =  surface->begin(); it != surface->end(); it++)
    {
        points[(i * array_x)] = (*it).x;
        points[(i * array_x) + 1] = (*it).y;
        i++;
    };
}

hfgl_polygon::hfgl_polygon(const hfgl_polygon& orig) 
{
}

void hfgl_polygon::clean()
{
    if (points)
    {
        delete[] points;
        points = NULL;
        array_x = 0;
        array_y = 0;
    };
}
hfgl_polygon::~hfgl_polygon()
{
    clean();
}

GLfloat* hfgl_polygon::getCoordinate(int pos)
{
    if (pos < array_y)
        return &points[pos * array_x];
    else 
        return NULL;
}